﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

namespace Avalon.Core.Configuration
{
    [Serializable]
    public class Configuration
    {
        [XmlAttribute]
        public string Name { get; set; }

        public List<AssemblyInformation> ViewModelAssemblies { get; set; }

        public List<AssemblyInformation> DataModelAssemblies { get; set; }

        public List<AssemblyInformation> PipelineAssemblies { get; set; }

        private Configuration() { }

        /// <summary>
        /// Return an instance of the configuration
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Configuration CreateConfiguration(string path)
        {
            string mappedPath = System.Web.HttpContext.Current.Server.MapPath(path);
            XmlSerializer serializer = new XmlSerializer(typeof(Configuration));
            using (FileStream fileStream = new FileStream(mappedPath, FileMode.Open))
            {
                Configuration configuration = (Configuration)serializer.Deserialize(fileStream);
                fileStream.Close();
                return configuration;
            }
            throw new NullReferenceException("");
        }
    }

}
